package com;



import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class JDBC {
    public static void main(String[] args) throws Exception{
        //注册驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        System.out.println("注册成功");
        //数据库连接对象
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/day02","root","root");
        //创建执行sql语句的对象
        Statement statement=conn.createStatement();
        String sql = "select * from teacher";
        //执行sql语句 接收结果
        ResultSet rs = statement.executeQuery(sql);
        //得到结果集
        System.out.println("姓名"+"    "+"年龄");
        while (rs.next()){
            System.out.println(rs.getString("name")+"    "+rs.getInt("age"));
        }
        conn.close();
        statement.close();
    }
}
